package com.crscd.ai.controller;

import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 10/11/25 3:45 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class MenuController {
  @Autowired private ChatModel chatModel;

  @GetMapping(value = "/eat")
  public Flux<String> eat(@RequestParam(name = "msg", defaultValue = "今天吃什么") String msg) {
    String info =
        """
                你是一个AI厨师助手,每次随机生成三个家常菜，并且提供这些家常菜的详细做法步骤，以HTML格式返回
                字数控制在1500字以内。
                """;
    // 系统消息
    SystemMessage systemMessage = new SystemMessage(info);
    // 用户消息
    UserMessage userMessage = new UserMessage(msg);

    Prompt prompt = new Prompt(userMessage, systemMessage);

    return chatModel.stream(prompt)
        .mapNotNull(response -> response.getResults().getFirst().getOutput().getText());
  }
}
